using System;
using System.Web.UI;
using SouthernLand.Common;
using SouthernLand.Common.BOL;

namespace SouthernLand.Controls
{
    public partial class Newsletter : UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            btSave.Click+=new EventHandler(btSave_Click);
        }

        protected void btSave_Click(object sender, EventArgs e)
        {
            if (NewsLetter.CheckEmail(txtEmail.Text.Trim()) == false)
            {
                var obj = new NewsLetter();
                obj.Company = string.Empty;
                obj.AddedDate = DateTime.Now;
                obj.Title = string.Empty;
                obj.FirstName = string.Empty;
                obj.LastName = string.Empty;
                obj.Email = txtEmail.Text.Trim();
                int isuccess = NewsLetter.Insert(obj);
                if (isuccess > 0)
                {
                    txtEmail.Text = string.Empty;
                    Response.Write("<script> alert('" + ResourceManager.GetString("Newsletter_DangkyThanhcong") +
                                   "') </script>");
                }

            }
            else
            {
                Response.Write("<script> alert('" + ResourceManager.GetString("Newsletter_DaTonTai") + "') </script>");
            }
        }
    }
}